/**
 * =================================================================
 * 版权所有 2011-2013 深圳市泰海网络科技服务有限公司，并保留所有权利
 * -----------------------------------------------------------------
 * 这不是一个自由软件！您不能在任何未经允许的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布
 * =================================================================
 */
package com.imoney.payment.member.handler;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.imoney.framework.base.entity.IRequest;
import com.imoney.framework.base.entity.Response;
import com.imoney.framework.base.exception.ServiceException;
import com.imoney.payment.account.domain.Account;
import com.imoney.payment.account.domain.AccountType;
import com.imoney.payment.account.enums.AccountStatus;
import com.imoney.payment.account.enums.ActType;
import com.imoney.payment.account.service.IAccountService;
import com.imoney.payment.account.service.IActTypeService;
import com.imoney.payment.chain.HandlerChain;
import com.imoney.payment.member.domain.Member;
import com.imoney.payment.member.domain.RegCompleteRequest;
import com.imoney.payment.trade.common.InfoCode;

/**
 * 类说明：账户初始化数据<br>
 * 
 * <p>
 * 详细描述：<br>
 * 
 * </p>
 * 
 * <pre>
 * ——————————————————————————————————————————————————————————————————
 * |		修改人		|		修改时间			|		修改原因
 * ——————————————————————————————————————————————————————————————————
 * |	zengxx 曾宪新	|		2013-6-6		|	
 * ——————————————————————————————————————————————————————————————————
 * </pre>
 * 
 * @author zengxx 曾宪新(Xavier.zeng)
 * 
 *         CreateDate: 2013-6-6
 */
@Service
public class InitAccountHandler extends AbstractHandler<Member> {

	@Resource
	private IActTypeService actTypeService;
	
	@Resource
	private IAccountService accountService;

	@Override
	public void doHandler(HandlerChain<Member> chain, IRequest request,
			Response<Member> response) throws ServiceException {
		RegCompleteRequest regRequest = (RegCompleteRequest) request;

		Account account = null;
		List<Account> accountList = new ArrayList<Account>();
		List<AccountType> actTypeList = actTypeService
				.queryActTypeList(ActType.COMMON);
		for (AccountType actType : actTypeList) {
			account = new Account(actType.getActTypeName(),
					actType.getActTypeNo(), response.getData().getMemberNo(),
					"", "1", regRequest.getPayPwd(), AccountStatus.NORMAL);
			
			accountList.add(account);
		}
		accountService.addAccountList(accountList);
		
		/** 处理下一个任务 */
		chain.doHandler(chain, request, response);
		response.setCode(InfoCode.SUCCEED);
	}

}
